package com.example.demo.websocket;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

public class WebSocketServer {
    public static void main(String[] args) throws Exception {
        Server server = new Server(8089);
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        server.setHandler(context);

        // 使用 ChatWebSocketServlet
        ServletHolder wsHolder = new ServletHolder(new ChatWebSocketServlet());
        context.addServlet(wsHolder, "/chat");

        try {
            server.start();
            server.join();
        } finally {
            server.stop();
        }
    }
}